package constant.milk.cashbook.asset;

import constant.milk.cashbook.R;
import constant.milk.cashbook.SuperActivity;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class NameActivity extends SuperActivity
{
	public static final String NAME_DATA = "NAME_DATA";
	
	private EditText nameEditText;
	private TextView realView;
	
	private Button checkButton;
	
	private InputMethodManager imm;
	
	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.name_activity);
		
		setTitle("이름");
		
		setGoneTipButton();
		
		setFindViewId();
		setOnClick();
		setData();
	}

	@Override
	protected void setFindViewId()
	{
		nameEditText = (EditText) findViewById(R.id.realNameEditText);
		realView = (TextView) findViewById(R.id.realNameView);
		
		checkButton = (Button) findViewById(R.id.checkButton);
	}

	@Override
	protected void setOnClick()
	{
		realView.setOnTouchListener(new OnTouchListener()
		{
			@Override
			public boolean onTouch(View v, MotionEvent event)
			{
				imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
				imm.hideSoftInputFromWindow(nameEditText.getWindowToken(), 0);
				nameEditText.clearFocus();
				
				return false;
			}
		});
		
		checkButton.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				Intent intent = new Intent();
				intent.putExtra(NAME_DATA, nameEditText.getText().toString());
				setResult(Activity.RESULT_OK, intent);
				finish();
			}
		});
	}

	@Override
	protected void setData()
	{
		Intent intent = getIntent();
		String name = intent.getStringExtra(NAME_DATA);
		
		nameEditText.setText(name);
		
		nameEditText.requestFocus();
	}

	@Override
	protected void tipButton()
	{
	}

}
